iT邦幫忙

第 12 屆 iThome 鐵人賽

0
自我挑戰組

30天菜鳥學 Linux 系列 第 32

32天-學習建立 Node image

  • 分享至 

  • xImage
  •  

今天進度 : Build your Node image | Docker Documentation


test@test:~$ mkdir demo; cd demo;
test@test:~/demo$ sudo apt install npm
test@test:~/demo$ npm init -y
Wrote to /home/test/demo/package.json:

{
  "name": "demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


test@test:~/demo$ npm install ronin-server ronin-mocks
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN demo@1.0.0 No description
npm WARN demo@1.0.0 No repository field.

+ ronin-mocks@0.1.6
+ ronin-server@0.1.3
added 110 packages from 68 contributors and audited 110 packages in 91.037s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

test@test:~/demo$ touch server.js
test@test:~/demo$ nano server.js 

GNU nano 4.8                                                                      server.js                                                                       Modified  
const ronin     = require( 'ronin-server' )
const mocks     = require( 'ronin-mocks' )

const server = ronin.server()

server.use( '/', mocks.server( server.Router(), false, true ) )
server.start()



今天安裝 npm 發現安裝真多東西...

啟用 node server

test@test:~/demo$ node server.js

之後開另外一個 ssh 視窗發請求測試看看

test@test:~$  curl --request POST \
>   --url http://localhost:8000/test \
>   --header 'content-type: application/json' \
>   --data '{
> "msg": "testing"
> }'
{"code":"success","payload":[{"msg":"testing","id":"14a38255-e434-4563-bf4e-4685fa6c8802","createDate":"2020-10-04T18:10:36.437Z"}]}

test@test:~$ curl http://localhost:8000/test
{"code":"success","meta":{"total":1,"count":1},"payload":[{"msg":"testing","id":"14a38255-e434-4563-bf4e-4685fa6c8802","createDate":"2020-10-04T18:10:36.437Z"}]}

原 ssh 視窗 log

test@test:~/demo$ node server.js
2020-10-04T18:10:36:4080  INFO: POST /test
2020-10-04T18:12:21:8400  INFO: GET /test

上一篇
31天-繼續學習 docker build
下一篇
33天-學習 SSH 正確登入的方式
系列文
30天菜鳥學 Linux 59
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言